'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports JCsTools.IdentityManager



'''<summary>
'''This is a test class for IdentityTest and is intended
'''to contain all IdentityTest Unit Tests
'''</summary>
<TestClass()> _
Public Class IdentityTest


    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = Value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''A test for ImageUrl
    '''</summary>
    <TestMethod()> _
    Public Sub ImageUrlTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)
        Dim expected As String = System.IO.Path.GetTempFileName
        Dim actual As String
        target.ImageUrl = expected
        actual = target.ImageUrl
        Assert.AreEqual(expected, actual, False)
    End Sub

    '''<summary>
    '''A test for Identifier
    '''</summary>
    <TestMethod()> _
    Public Sub IdentifierTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)

        Assert.AreEqual(id, target.Identifier, "Identifier provided by constructor not set.")

        Dim expected As String = Guid.NewGuid.ToString

        target.Identifier = expected

        Assert.AreEqual(expected, target.Identifier, "Identifier provided by Property not set.")
    End Sub

    '''<summary>
    '''A test for Description
    '''</summary>
    <TestMethod()> _
    Public Sub DescriptionTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)
        Dim expected As String = Guid.NewGuid.ToString
        Dim actual As String
        target.Description = expected
        actual = target.Description
        Assert.AreEqual(expected, actual)
    End Sub

    '''<summary>
    '''A test for SetAttribute
    '''</summary>
    <TestMethod()> _
    Public Sub GetSetAttributeTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)

        Dim key As String = Guid.NewGuid.ToString
        Dim value As Object = New Object()
        Dim actual As Object

        target.SetAttribute(key, value)

        actual = target.GetAttribute(key)

        Assert.AreEqual(value, actual)
    End Sub

    '''<summary>
    '''A test for SetAttribute
    '''</summary>
    <TestMethod()> _
    Public Sub GetSetAttributeGenericTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)

        Dim attribute As TestAttribute = New TestAttribute
        Dim value As String = Guid.NewGuid.ToString
        Dim actual As String

        target.SetAttribute(attribute, value)

        actual = target.GetAttribute(attribute)

        Assert.AreEqual(value, actual)
    End Sub

    Public Class TestAttribute
        Implements JCsTools.IdentityManager.IIdentityAttribute(Of String)

        Public ReadOnly Property AttributeName() As String Implements IIdentityAttribute.AttributeName
            Get
                Return "TestAttribute"
            End Get
        End Property
    End Class


    '''<summary>
    '''A test for GetAttributeNames
    '''</summary>
    <TestMethod()> _
    Public Sub GetAttributeNamesTest()
        Dim id As String = Guid.NewGuid.ToString
        Dim target As IIdentity = New Identity(id)

        Dim expected As System.Collections.Generic.List(Of String)

        expected = New System.Collections.Generic.List(Of String)

        For i = 1 To 5
            Dim attributeName As String
            attributeName = Guid.NewGuid.ToString
            target.SetAttribute(attributeName, New Object())
            expected.Add(attributeName)
        Next

        Dim actual As System.Collections.Generic.List(Of String)

        actual = target.GetAttributeNames.ToList
        Assert.AreEqual(expected.Count, actual.Count, "The array lenghts do not match.")

        For Each item In expected
            Assert.IsTrue(actual.Contains(item), "Item not found in actual list.")
        Next
    End Sub
End Class
